/*
 * main.cpp
 *
 *  Created on: Jan 9, 2012
 *      Author: dblyth
 */

#include <iostream>
using namespace std;

#include "CorrCoeff.h"
#include "InlineStream.h"

int main(int argc, char** argv) {
	if (argc < 2) {
		cout << "Provide random number generator seed as sole argument" << endl;
		return 0;
	}

	unsigned int const sourceRefSize = 48;
	double* const sourceRef = new double[sourceRefSize] { -0.000966429, -0.00119964, -0.00118616, -0.000678582,
			0.00229951, 0.0217842, 0.0613074, 0.156733, 0.305301, 0.49182, 0.68358, 0.845512, 0.950986, 0.984521,
			0.944636, 0.842791, 0.687357, 0.527077, 0.380956, 0.260087, 0.168696, 0.105998, 0.0685462, 0.0484331,
			0.0353872, 0.0332753, 0.0334183, 0.0331892, 0.0318952, 0.0299273, 0.0283969, 0.0277491, 0.0273934,
			0.0265412, 0.0250565, 0.0232322, 0.0213166, 0.0190748, 0.0159684, 0.0131479, 0.0104398, 0.00725754,
			0.00329131, 0.00210918, 0.00147583, 0.000903992, 0.000475297, 0.000122942 };

	unsigned int const numSamples = 48;
	unsigned int const numPeaks = 1;
	unsigned long const seed = atoi(argv[1]);
	/*
	 * InlineStream defined elsewhere.  Purpose is to randomly size and place
	 * sourceRef with statistical fluctuation.  Uses cubic interpolation to
	 * fine tune placement.
	 */
	InlineStream IS(numSamples, numPeaks, seed, sourceRef, sourceRefSize);

	double ref[21] = { 0.0217842, 0.0613074, 0.156733, 0.305301, 0.49182, 0.68358, 0.845512, 0.950986, 0.984521,
			0.944636, 0.842791, 0.687357, 0.527077, 0.380956, 0.260087, 0.168696, 0.105998, 0.0685462, 0.0484331,
			0.0353872, 0.0332753 };

	CorrCoeff<unsigned short> corrcoeff(ref, 0.7);

	bool* isOver = new bool[numSamples - 21 + 1];
	double* coeff = new double[numSamples - 21 + 1];

	corrcoeff.getCoeffsOverThres(IS.stream, numSamples, isOver, coeff);

	for (int i = 0; i < numSamples - 21 + 1; i++) {
		string isover = "false";
		if (isOver[i])
			isover = "true";
		cout << "Index:\t" << i << "\tStream_value:\t" << IS.stream[i] << "\tIs_over:\t" << isover
				<< "\tCoefficient:\t" << coeff[i] << endl;
	}

	cout << endl;

	for (int i = 0; i < numPeaks; i++)
		cout << "Peak size:\t" << IS.peakInfo[i][0] << "\tPeak pos:\t" << IS.peakInfo[i][1] << endl;

	cout << endl << "hasOverThres() = ";
	bool hasCoeffOverThres = corrcoeff.hasCoeffOverThres(IS.stream, numSamples);
	if (hasCoeffOverThres)
		cout << "true";
	else
		cout << "false";
	cout << endl;

	return 0;
}
